package ar.com.photo_admin.domain

import grails.plugins.springsecurity.Secured

@Secured(["isAuthenticated()"])
class NotificationsConfigurationController {

	def springSecurityService 
	
    def index() {
		redirect(action: "configuration")
	}
		
	def configuration() {
		def notificationsInstance = springSecurityService.getCurrentUser().notificationsConfiguration
		[notificationsInstance: notificationsInstance]
	}
	
	def save() {
		def notificationsInstance = springSecurityService.getCurrentUser().notificationsConfiguration
		notificationsInstance.properties = params

		if (notificationsInstance.hasErrors() || !notificationsInstance.save(flush: true)) {
			render(view: "configuration", model: [notificationsInstance: notificationsInstance])
			return
		}
				
		flash.message = message(code: 'userInstance.notificationsConfiguration.update')
		render(view: "configuration", model: [notificationsInstance: notificationsInstance])
	}
}
